home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume22 / pathalias10 / part03 < prev    next >
Encoding:
Internet Message Format  |  1990-06-07  |  24.7 KB

  1. Subject:  v22i111:  Pathalias, version 10, Part03/03
  2. Newsgroups: comp.sources.unix
  3. Approved: rsalz@uunet.UU.NET
  4. X-Checksum-Snefru: 9d5358d9 25b4e552 c54329d9 b85b4742
  5.  
  6. Submitted-by: peter honeyman <honey@citi.umich.edu>
  7. Posting-number: Volume 22, Issue 111
  8. Archive-name: pathalias10/part03
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then feed it
  12. # into a shell via "sh file" or similar.  To overwrite existing files,
  13. # type "sh file -c".
  14. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  15. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  16. # Contents:  CHANGES Makefile config.h def.h local.c main.c make.honey
  17. #   makedb.c
  18. # Wrapped by rsalz@litchi.bbn.com on Fri Jun  8 09:25:22 1990
  19. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  20. echo If this archive is complete, you will see the following message:
  21. echo '          "shar: End of archive 3 (of 3)."'
  22. if test -f 'CHANGES' -a "${1}" != "-c" ; then 
  23.   echo shar: Will not clobber existing file \"'CHANGES'\"
  24. else
  25.   echo shar: Extracting \"'CHANGES'\" \(1202 characters\)
  26.   sed "s/^X//" >'CHANGES' <<'END_OF_FILE'
  27. XNets without names.
  28. XAllow negative cost components; prohibit negative costs.
  29. XNew input syntax: adjust {host, ...}; kill -a option.
  30. XNew input syntax: file {filename}.
  31. XNew input syntax: delete {host, host!neighbor}.
  32. XTerminal nets.
  33. XPrevent back links to domains.
  34. X
  35. X-- mod.sources, 10/87 -- version 9
  36. XTerminal edges and domains (<host> syntax and -D option).
  37. XDead hosts and edges in the input stream.
  38. XEmpty private list ends scope of privates.
  39. XFirst hop cost in output (-f option).
  40. XPenalize deprecated hosts (-a option).
  41. X
  42. X-- mod.sources, 4.3bsd, 1/86 -- version 8
  43. XImproved alias treatment.
  44. XRoutes to domain gateways.
  45. XLeading dot in name implies domain.
  46. XLink/host tracing (-t option).
  47. XUse getopt().
  48. X
  49. X-- mod.sources, 8/85 -- version 7
  50. XPrivate hosts documented.
  51. XHomegrown scanner -- it was true what they said about lex.
  52. XMakedb.
  53. XDomains and gateways.
  54. XDEAD back link.
  55. X
  56. X-- net.sources, 1/85 -- version 6
  57. XNo ! in dbm key.
  58. XNetwork character must be one of !@%: -- dot is dead.
  59. XPrivate hosts.
  60. XDiscourage hybrid addresses.  
  61. XMagic @ <-> % rule.
  62. X
  63. X-- 1983-1984 -- version 5
  64. XReverse sense of the -c (cost) flag.
  65. XUse cheapest among duplicate links.
  66. XElide network names in output.
  67. X
  68. X-- epoch (smb version) -- versions 1-4
  69. END_OF_FILE
  70.   if test 1202 -ne `wc -c <'CHANGES'`; then
  71.     echo shar: \"'CHANGES'\" unpacked with wrong size!
  72.   fi
  73.   # end of 'CHANGES'
  74. fi
  75. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  76.   echo shar: Will not clobber existing file \"'Makefile'\"
  77. else
  78.   echo shar: Extracting \"'Makefile'\" \(1354 characters\)
  79.   sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  80. X#!/bin/make -f
  81. X# pathalias -- by steve bellovin, as told to peter honeyman
  82. X
  83. X### begin configuration section
  84. X###
  85. X# if you can't or don't intend to use dbm files,
  86. X# don't bother with DBM or makedb
  87. XDBM = -ldbm
  88. X# or if you roll your own ...
  89. X# DBM = dbm.o
  90. X###
  91. X# where is getopt (if not in the c library)?
  92. X# GETOPT = getopt.o
  93. X### end of configuration section 
  94. X
  95. X
  96. XCC = cc
  97. XCFLAGS = -O
  98. XLDFLAGS = -s $(GETOPT)
  99. XYFLAGS = -d
  100. X
  101. XOBJ = addlink.o addnode.o local.o main.o mapit.o mapaux.o mem.o parse.o printit.o
  102. XHDRS = def.h config.h
  103. XCSRC = addlink.c addnode.c local.c main.c mapit.c mapaux.c mem.c printit.c
  104. XLSRC = $(CSRC) parse.c
  105. XSRC = $(CSRC) parse.y makedb.c arpatxt.c
  106. X
  107. Xpathalias: $(OBJ)
  108. X    $(CC) $(OBJ) $(LDFLAGS) -o pathalias
  109. X
  110. Xall: pathalias makedb arpatxt
  111. X
  112. X$(OBJ):    $(HDRS)
  113. X
  114. Xparse.c: parse.y $(HDRS)
  115. X    $(YACC) $(YFLAGS) parse.y
  116. X    mv y.tab.c parse.c
  117. X
  118. Xmakedb: makedb.o
  119. X    $(CC) makedb.o $(LDFLAGS) $(DBM) -o makedb
  120. X
  121. Xmakedb.o: config.h
  122. X
  123. Xarpatxt: arpatxt.o
  124. X    $(CC) arpatxt.o $(LDFLAGS) -o arpatxt
  125. X
  126. Xclean:
  127. X    rm -f *.o y.tab.? parse.c
  128. X
  129. Xclobber: clean
  130. X    rm -f pathalias makedb arpatxt
  131. X
  132. Xtags: $(SRC) $(HDRS)
  133. X    ctags -w $(HDRS) $(SRC)
  134. X
  135. Xbundle:
  136. X    @bundle README CHANGES pathalias.1 Makefile ${HDRS} ${SRC}
  137. X
  138. Xlint:    $(LSRC)
  139. X    lint $(CFLAGS) $(LSRC)
  140. X    lint makedb.c
  141. X    lint arpatxt.c
  142. X
  143. Xinstall:
  144. X    @echo "install pathalias, makedb, arpatxt, and pathalias.1"
  145. X    @echo "according to local conventions"
  146. END_OF_FILE
  147.   if test 1354 -ne `wc -c <'Makefile'`; then
  148.     echo shar: \"'Makefile'\" unpacked with wrong size!
  149.   fi
  150.   # end of 'Makefile'
  151. fi
  152. if test -f 'config.h' -a "${1}" != "-c" ; then 
  153.   echo shar: Will not clobber existing file \"'config.h'\"
  154. else
  155.   echo shar: Extracting \"'config.h'\" \(2426 characters\)
  156.   sed "s/^X//" >'config.h' <<'END_OF_FILE'
  157. X/* pathalias -- by steve bellovin, as told to peter honeyman */
  158. X
  159. X/**************************************************************************
  160. X * +--------------------------------------------------------------------+ *
  161. X * |                    begin configuration section                     | *
  162. X * +--------------------------------------------------------------------+ *
  163. X **************************************************************************/
  164. X
  165. X#undef STRCHR        /* have strchr -- system v and many others */
  166. X
  167. X#undef UNAME        /* have uname() -- probably system v or 8th ed. */
  168. X#undef MEMSET        /* have memset() -- probably system v or 8th ed. */
  169. X
  170. X#define GETHOSTNAME    /* have gethostname() -- probably bsd */
  171. X#define BZERO        /* have bzero() -- probably bsd */
  172. X
  173. X/* default place for dbm output of makedb (or use -o at run-time) */
  174. X#define    ALIASDB    "/usr/local/lib/palias"
  175. X
  176. X/**************************************************************************
  177. X * +--------------------------------------------------------------------+ *
  178. X * |                    end of configuration section                    | *
  179. X * +--------------------------------------------------------------------+ *
  180. X **************************************************************************/
  181. X
  182. X
  183. X
  184. X#ifdef MAIN
  185. X#ifndef lint
  186. Xstatic char    *c_sccsid = "@(#)config.h    9.2 89/03/03";
  187. X#endif /*lint*/
  188. X#endif /*MAIN*/
  189. X
  190. X/*
  191. X * malloc/free fine tuned for pathalias.
  192. X *
  193. X * MYMALLOC should work everwhere, so it's not a configuration
  194. X * option (anymore).  nonetheless, if you're getting strange
  195. X * core dumps (or panics!), comment out the following manifest,
  196. X * and use the inferior C library malloc/free.
  197. X */
  198. X#define MYMALLOC    /**/
  199. X
  200. X#ifdef MYMALLOC
  201. X#define malloc mymalloc
  202. X#define calloc(n, s) malloc ((n)*(s))
  203. X#define free(s)
  204. X#define cfree(s)
  205. Xextern char *memget();
  206. X#else /* !MYMALLOC */
  207. Xextern char *calloc();
  208. X#endif /* MYMALLOC */
  209. X
  210. X#ifdef STRCHR
  211. X#define index strchr
  212. X#define rindex strrchr
  213. X#else
  214. X#define strchr index
  215. X#define strrchr rindex
  216. X#endif
  217. X
  218. X#ifdef BZERO
  219. X#define strclear(s, n)    ((void) bzero((s), (n)))
  220. X#else /*!BZERO*/
  221. X
  222. X#ifdef MEMSET
  223. Xextern char    *memset();
  224. X#define strclear(s, n)    ((void) memset((s), 0, (n)))
  225. X#else /*!MEMSET*/
  226. Xextern void    strclear();
  227. X#endif /*MEMSET*/
  228. X
  229. X#endif /*BZERO*/
  230. X
  231. Xextern char    *malloc();
  232. Xextern char    *strcpy(), *index(), *rindex();
  233. X
  234. X#ifndef STATIC
  235. X
  236. X#ifdef DEBUG
  237. X#define STATIC extern
  238. X#else /*DEBUG*/
  239. X#define STATIC static
  240. X#endif /*DEBUG*/
  241. X
  242. X#endif /*STATIC*/
  243. END_OF_FILE
  244.   if test 2426 -ne `wc -c <'config.h'`; then
  245.     echo shar: \"'config.h'\" unpacked with wrong size!
  246.   fi
  247.   # end of 'config.h'
  248. fi
  249. if test -f 'def.h' -a "${1}" != "-c" ; then 
  250.   echo shar: Will not clobber existing file \"'def.h'\"
  251. else
  252.   echo shar: Extracting \"'def.h'\" \(4496 characters\)
  253.   sed "s/^X//" >'def.h' <<'END_OF_FILE'
  254. X/* pathalias -- by steve bellovin, as told to peter honeyman */
  255. X
  256. X#ifndef lint
  257. X#ifdef MAIN
  258. Xstatic char    *h_sccsid = "@(#)def.h    9.5 88/05/09";
  259. X#endif /*MAIN*/
  260. X#endif /*lint*/
  261. X
  262. X#include <stdio.h>
  263. X#include <ctype.h>
  264. X#include "config.h"
  265. X
  266. Xtypedef    long Cost;
  267. Xtypedef struct node node;
  268. Xtypedef struct link link;
  269. X
  270. X#ifdef lint
  271. X#define vprintf fprintf
  272. X#else /*!lint -- this gives null effect warning*/
  273. X/* because it's there ... */
  274. X#define vprintf        !Vflag ? 0 : fprintf
  275. X#endif /*lint*/
  276. X
  277. X#define NTRACE    16    /* can trace up to NTRACE hosts/links */
  278. X
  279. X/* flags for n_flag */
  280. X#define ISPRIVATE  0x0001 /* invisible outside its definition file */
  281. X#define NALIAS       0x0002 /* heaped as an alias */
  282. X#define ATSIGN       0x0004 /* seen an at sign?  used for magic @/% rules */
  283. X#define MAPPED       0x0008 /* extracted from heap */
  284. X#define    NDEAD       0x0010 /* out links are dead */
  285. X#define HASLEFT       0x0020 /* has a left side net character */
  286. X#define HASRIGHT   0x0040 /* route has a right side net character */
  287. X#define    NNET       0x0080 /* network pseudo-host */
  288. X#define INDFS       0x0100 /* used when removing net cycles (for -g) */
  289. X#define DUMP       0x0200 /* we have dumped this net's edges (for -g) */
  290. X#define PRINTED       0x0400 /* this host has been printed */
  291. X#define NTERMINAL  0x0800 /* heaped as terminal edge (or alias thereto) */
  292. X#define NREF       0x1000 /* node has an "interesting" reference */
  293. X
  294. X#define ISADOMAIN(n)     ((n)->n_name[0] == '.')
  295. X#define ISANET(n)     (((n)->n_flag & NNET) || ISADOMAIN(n))
  296. X#define ALTEREGO(n1, n2) ((n1)->n_name == (n2)->n_name)
  297. X#define DEADHOST(n)     (((n)->n_flag & (NDEAD | NTERMINAL)) && !ISANET(n))
  298. X#define DEADLINK(l)     ((l)->l_flag & LDEAD)
  299. X#define DEADNET(n)     (((n)->n_flag & (NNET | NDEAD)) == (NNET | NDEAD))
  300. X#define GATEWAYED(n)     (DEADNET(n) || ISADOMAIN(n))
  301. X
  302. X#ifndef DEBUG
  303. X/*
  304. X * save some space in nodes -- there are > 10,000 allocated!
  305. X */
  306. X
  307. X#define n_root un1.nu_root
  308. X#define n_net un1.nu_net
  309. X#define n_copy un1.nu_copy
  310. X
  311. X#define n_private un2.nu_priv
  312. X#define n_parent  un2.nu_par
  313. X
  314. X/* WARNING: if > 2^16 nodes, type of n_tloc must change */
  315. Xstruct node {
  316. X    char    *n_name;    /* host name */
  317. X    link    *n_link;    /* adjacency list */
  318. X    Cost    n_cost;        /* cost to this host */
  319. X    union {
  320. X        node *nu_net;    /* others in this network (parsing) */
  321. X        node *nu_root;    /* root of net cycle (graph dumping) */
  322. X        node *nu_copy;    /* circular copy list (mapping) */
  323. X    } un1;
  324. X    union {
  325. X        node *nu_priv;    /* other privates in this file (parsing) */
  326. X        node *nu_par;    /* parent in shortest path tree (mapping) */
  327. X    } un2;
  328. X    unsigned short n_tloc;    /* back ptr to heap/hash table */
  329. X    unsigned short n_flag;        /* see manifests above */
  330. X};
  331. X
  332. X#endif /*DEBUG*/
  333. X
  334. X#define MILLION (1000L * 1000L)
  335. X#define    DEFNET    '!'            /* default network operator */
  336. X#define    DEFDIR    LLEFT            /* host on left is default */
  337. X#define    DEFCOST    ((Cost) 4000)        /* default cost of a link */
  338. X#define    INF    ((Cost) 100 * MILLION)    /* infinitely expensive link */
  339. X#define DEFPENALTY ((Cost) 200)        /* default avoidance cost */
  340. X
  341. X/* data structure for adjacency list representation */
  342. X
  343. X/* flags for l_dir */
  344. X
  345. X#define NETDIR(l)    ((l)->l_flag & LDIR)
  346. X#define NETCHAR(l)    ((l)->l_netop)
  347. X
  348. X#define LDIR      0x0008    /* 0 for left, 1 for right */
  349. X#define LRIGHT      0x0000    /* user@host style */
  350. X#define LLEFT      0x0008    /* host!user style */
  351. X
  352. X#define LDEAD      0x0010    /* this link is dead */
  353. X#define LALIAS      0x0020    /* this link is an alias */
  354. X#define LTREE      0x0040    /* member of shortest path tree */
  355. X#define LGATEWAY  0x0080    /* this link is a gateway */
  356. X#define LTERMINAL 0x0100    /* this link is terminal */
  357. X
  358. X#ifndef DEBUG
  359. X/*
  360. X * borrow a field for link/node tracing.  there's a shitload of
  361. X * edges -- every word counts.  only so much squishing is possible:
  362. X * alignment dictates that the size be a multiple of four.
  363. X */
  364. X
  365. X#define l_next un.lu_next
  366. X#define l_from un.lu_from
  367. X
  368. Xstruct link {
  369. X    node    *l_to;        /* adjacent node */
  370. X    Cost    l_cost;        /* edge cost */
  371. X    union {
  372. X        link *lu_next;    /* rest of adjacency list (not tracing) */
  373. X        node *lu_from;    /* source node (tracing) */
  374. X    } un;
  375. X    short    l_flag;        /* right/left syntax, flags */
  376. X    char    l_netop;    /* network operator */
  377. X};
  378. X
  379. X#endif /*DEBUG*/
  380. X
  381. X#ifdef DEBUG
  382. X/*
  383. X * flattening out the unions makes it easier
  384. X * to debug (when pi is unavailable).
  385. X */
  386. Xstruct node {
  387. X    char    *n_name;
  388. X    link    *n_link;
  389. X    Cost    n_cost;
  390. X    node    *n_net;
  391. X    node    *n_root;
  392. X    node    *n_copy;
  393. X    node    *n_private;
  394. X    node    *n_parent;
  395. X    unsigned short n_tloc;
  396. X    unsigned short n_flag;
  397. X};
  398. Xstruct link {
  399. X    node    *l_to;
  400. X    Cost    l_cost;
  401. X    link    *l_next;
  402. X    node    *l_from;
  403. X    short    l_flag;
  404. X    char    l_netop;
  405. X};
  406. X#endif /*DEBUG*/
  407. END_OF_FILE
  408.   if test 4496 -ne `wc -c <'def.h'`; then
  409.     echo shar: \"'def.h'\" unpacked with wrong size!
  410.   fi
  411.   # end of 'def.h'
  412. fi
  413. if test -f 'local.c' -a "${1}" != "-c" ; then 
  414.   echo shar: Will not clobber existing file \"'local.c'\"
  415. else
  416.   echo shar: Extracting \"'local.c'\" \(1554 characters\)
  417.   sed "s/^X//" >'local.c' <<'END_OF_FILE'
  418. X/* pathalias -- by steve bellovin, as told to peter honeyman */
  419. X#ifndef lint
  420. Xstatic char    *sccsid = "@(#)local.c    9.2 88/06/10";
  421. X#endif /* lint */
  422. X
  423. X#include <stdio.h>
  424. X#include "config.h"
  425. X
  426. X#ifdef    UNAME
  427. X#include <sys/utsname.h>
  428. X
  429. Xchar    *
  430. Xlocal()
  431. X{
  432. X    static struct utsname utsname;
  433. X    extern int uname();
  434. X
  435. X    (void) uname(&utsname);
  436. X    return(utsname.nodename);
  437. X}
  438. X
  439. X#else /* !UNAME */
  440. X
  441. Xchar    *
  442. Xlocal()
  443. X{
  444. X    static char lname[64];
  445. X    extern int gethostname();
  446. X
  447. X    (void) gethostname(lname, (int) sizeof(lname));
  448. X    lname[sizeof(lname)] = 0;
  449. X    return(lname);
  450. X}
  451. X
  452. X#ifndef GETHOSTNAME
  453. X
  454. XSTATIC int
  455. Xgethostname(name, len)
  456. X    char *name;
  457. X    int len;
  458. X{    FILE *whoami;
  459. X    char *ptr;
  460. X    extern int pclose();
  461. X    extern FILE *fopen(), *popen();
  462. X
  463. X    *name = '\0';
  464. X
  465. X    /* try /etc/whoami */
  466. X    if ((whoami = fopen("/etc/whoami", "r")) != 0) {
  467. X        (void) fgets(name, len, whoami);
  468. X        (void) fclose(whoami);
  469. X        if ((ptr = index(name, '\n')) != 0)
  470. X            *ptr = '\0';
  471. X    }
  472. X    if (*name)
  473. X        return 0;
  474. X
  475. X    /* try /usr/include/whoami.h */
  476. X    if ((whoami = fopen("/usr/include/whoami.h", "r")) != 0) {
  477. X        while (!feof(whoami)) {
  478. X            char    buf[100];
  479. X
  480. X            if (fgets(buf, 100, whoami) == 0)
  481. X                break;
  482. X            if (sscanf(buf, "#define sysname \"%[^\"]\"", name))
  483. X                break;
  484. X        }
  485. X        (void) fclose(whoami);
  486. X        if (*name)
  487. X            return 0;
  488. X    }
  489. X
  490. X    /* ask uucp */
  491. X    if ((whoami = popen("uuname -l", "r")) != 0) {
  492. X        (void) fgets(name, len, whoami);
  493. X        (void) pclose(whoami);
  494. X        if ((ptr = index(name, '\n')) != 0)
  495. X            *ptr = '\0';
  496. X    }
  497. X    if (*name)
  498. X        return 0;
  499. X    
  500. X    /* aw hell, i give up!  is this really unix? */
  501. X    return -1;
  502. X}
  503. X#endif /* GETHOSTNAME */
  504. X#endif /* UNAME */
  505. END_OF_FILE
  506.   if test 1554 -ne `wc -c <'local.c'`; then
  507.     echo shar: \"'local.c'\" unpacked with wrong size!
  508.   fi
  509.   # end of 'local.c'
  510. fi
  511. if test -f 'main.c' -a "${1}" != "-c" ; then 
  512.   echo shar: Will not clobber existing file \"'main.c'\"
  513. else
  514.   echo shar: Extracting \"'main.c'\" \(3827 characters\)
  515.   sed "s/^X//" >'main.c' <<'END_OF_FILE'
  516. X/* pathalias -- by steve bellovin, as told to peter honeyman */
  517. X#ifndef lint
  518. Xstatic char    *sccsid = "@(#)main.c    9.5 88/06/10";
  519. X#endif
  520. X
  521. X#define MAIN    /* for sccsid in header files */
  522. X
  523. X#include "def.h"
  524. X
  525. X/* exports */
  526. Xchar *Cfile;    /* current input file */
  527. Xchar *Graphout;    /* file for dumping edges (-g option) */
  528. Xchar *Linkout;    /* file for dumping shortest path tree */
  529. Xchar **Argv;    /* external copy of argv (for input files) */
  530. Xnode *Home;    /* node for local host */
  531. Xint Cflag;    /* print costs (-c option) */
  532. Xint Dflag;    /* penalize routes beyond domains (-D option) */
  533. Xint Iflag;    /* ignore case (-i option) */
  534. Xint Tflag;    /* trace links (-t option) */
  535. Xint Vflag;    /* verbose (-v option) */
  536. Xint Fflag;    /* print cost of first hop */
  537. Xint Lineno = 1;    /* line number within current input file */
  538. Xint Argc;    /* external copy of argc (for input files) */
  539. Xextern void die();
  540. Xextern int tracelink();
  541. X
  542. X/* imports */
  543. Xextern char *optarg;
  544. Xextern int optind;
  545. Xextern long Lcount, Ncount;
  546. Xextern long allocation();
  547. Xextern void wasted(), mapit(), hashanalyze(), deadlink();
  548. Xextern char *local();
  549. Xextern node *addnode();
  550. Xextern int getopt(), yyparse();
  551. Xextern void printit();
  552. X
  553. X#define USAGE "usage: %s [-vciDf] [-l localname] [-d deadlink] [-t tracelink] [-g edgeout] [-s treeout] [-a avoid] [files ...]\n"
  554. X
  555. Xmain(argc, argv) 
  556. X    register int argc; 
  557. X    register char **argv;
  558. X{    char *locname = 0, *bang;
  559. X    register int c;
  560. X    int errflg = 0;
  561. X
  562. X    setbuf(stderr, (char *) 0);
  563. X    (void) allocation();    /* initialize data space monitoring */
  564. X    Cfile = "[deadlinks]";    /* for tracing dead links */
  565. X    Argv = argv;
  566. X    Argc = argc;
  567. X
  568. X    while ((c = getopt(argc, argv, "cd:Dfg:il:s:t:v")) != EOF)
  569. X        switch(c) {
  570. X        case 'c':    /* print cost info */
  571. X            Cflag++;
  572. X            break;
  573. X        case 'd':    /* dead host or link */
  574. X            if ((bang = index(optarg, '!')) != 0) {
  575. X                *bang++ = 0;
  576. X                deadlink(addnode(optarg), addnode(bang));
  577. X            } else
  578. X                deadlink(addnode(optarg), (node *) 0);
  579. X            break;
  580. X        case 'D':    /* penalize routes beyond domains */
  581. X            Dflag++;
  582. X            break;
  583. X        case 'f':    /* print cost of first hop */
  584. X            Cflag++;
  585. X            Fflag++;
  586. X            break;
  587. X        case 'g':    /* graph output file */
  588. X            Graphout = optarg;
  589. X            break;
  590. X        case 'i':    /* ignore case */
  591. X            Iflag++;
  592. X            break;
  593. X        case 'l':    /* local name */
  594. X            locname = optarg;
  595. X            break;
  596. X        case 's':    /* show shortest path tree */
  597. X            Linkout = optarg;
  598. X            break;
  599. X        case 't':    /* trace this link */
  600. X            if (tracelink(optarg) < 0) {
  601. X                fprintf(stderr, "%s: can trace only %d links\n", Argv[0], NTRACE);
  602. X                exit(1);
  603. X            }
  604. X            Tflag = 1;
  605. X            break;
  606. X        case 'v':    /* verbose stderr, mixed blessing */
  607. X            Vflag++;
  608. X            break;
  609. X        default:
  610. X            errflg++;
  611. X        }
  612. X
  613. X    if (errflg) {
  614. X        fprintf(stderr, USAGE, Argv[0]);
  615. X        exit(1);
  616. X    }
  617. X    argv += optind;        /* kludge for yywrap() */
  618. X
  619. X    if (*argv)
  620. X        freopen("/dev/null", "r", stdin);
  621. X    else
  622. X        Cfile = "[stdin]";
  623. X
  624. X    if (!locname) 
  625. X        locname = local();
  626. X    if (*locname == 0) {
  627. X        locname = "lostinspace";
  628. X        fprintf(stderr, "%s: using \"%s\" for local name\n",
  629. X                Argv[0], locname);
  630. X    }
  631. X
  632. X    Home = addnode(locname);    /* add home node */
  633. X    Home->n_cost = 0;        /* doesn't cost to get here */
  634. X
  635. X    (void) yyparse();            /* read in link info */
  636. X
  637. X    if (Vflag > 1)
  638. X        hashanalyze();
  639. X    vprintf(stderr, "%d nodes, %d links, alloc %ldk\n", 
  640. X                Ncount, Lcount, allocation());
  641. X
  642. X    Cfile = "[backlinks]";    /* for tracing back links */
  643. X    Lineno = 0;
  644. X
  645. X    /* compute shortest path tree */
  646. X    mapit();
  647. X    vprintf(stderr, "allocation is %ldk after mapping\n", allocation());
  648. X
  649. X    /* traverse tree and print paths */
  650. X    printit();
  651. X    vprintf(stderr, "allocation is %ldk after printing\n", allocation());
  652. X
  653. X    wasted();    /* how much was wasted in memory allocation? */
  654. X
  655. X    return 0;
  656. X}
  657. X
  658. Xvoid
  659. Xdie(s)
  660. X    char *s;
  661. X{
  662. X#ifdef DEBUG
  663. X    extern int abort();
  664. X
  665. X    fprintf(stderr, "%s: %s\n", Argv[0], s);
  666. X    fflush(stdout);
  667. X    fflush(stderr);
  668. X    abort();
  669. X#else
  670. X    fprintf(stderr, "%s: %s; notify the authorities\n", Argv[0], s);
  671. X    exit(-1);
  672. X#endif
  673. X}
  674. END_OF_FILE
  675.   if test 3827 -ne `wc -c <'main.c'`; then
  676.     echo shar: \"'main.c'\" unpacked with wrong size!
  677.   fi
  678.   # end of 'main.c'
  679. fi
  680. if test -f 'make.honey' -a "${1}" != "-c" ; then 
  681.   echo shar: Will not clobber existing file \"'make.honey'\"
  682. else
  683.   echo shar: Extracting \"'make.honey'\" \(3090 characters\)
  684.   sed "s/^X//" >'make.honey' <<'END_OF_FILE'
  685. X#!/bin/make -f
  686. X# pathalias -- by steve bellovin, as told to peter honeyman
  687. X
  688. X### configuration section
  689. X###
  690. X# if you can't or don't intend to use dbm files,
  691. X# don't bother with DBM or makedb
  692. XDBM = -ldbm
  693. X# or if you roll your own ...
  694. X# DBM = dbm.o
  695. X###
  696. X# where is getopt (if not in the c library)?
  697. X# GETOPT = -lgetopt
  698. X### end of configuration section 
  699. X
  700. XCC = cc -g
  701. XCFLAGS =  -DDEBUG
  702. XLDFLAGS =
  703. XYFLAGS = -dD
  704. XYYDEBUG=0
  705. X
  706. XOBJ = addlink.o addnode.o local.o main.o mapit.o mapaux.o mem.o parse.o printit.o
  707. XOFILES = addlink.O addnode.O local.O main.O mapit.O mapaux.O mem.O parse.O printit.O
  708. XHDRS = def.h config.h
  709. XCSRC = addlink.c addnode.c local.c main.c mapit.c mapaux.c mem.c printit.c
  710. XLSRC = $(CSRC) parse.c
  711. XSRC = $(CSRC) parse.y makedb.c arpatxt.c
  712. X
  713. Xpathalias: & $(OBJ)
  714. X    $(CC) $(OBJ) $(LDFLAGS) -o pathalias
  715. X
  716. Xall: pathalias makedb arpatxt
  717. X
  718. X$(OBJ):    $(HDRS)
  719. X
  720. Xparse.c: parse.y $(HDRS)
  721. X    $(YACC) $(YFLAGS) parse.y
  722. X    echo '#define YYDEBUG' > parse.c
  723. X    sed -e '/^# line/d' -e 's/yydebug = 0/yydebug = $(YYDEBUG)/' y.tab.c >> parse.c
  724. X
  725. Xmakedb: makedb.o
  726. X    $(CC) makedb.o $(LDFLAGS) $(DBM) -o makedb
  727. X
  728. Xmakedb.o: config.h
  729. X
  730. Xarpatxt: arpatxt.o
  731. X    $(CC) arpatxt.o $(LDFLAGS) -o arpatxt
  732. X
  733. Xclean:
  734. X    rm -f *.o y.tab.? parse.c
  735. X
  736. Xtags: $(SRC) $(HDRS)
  737. X    ctags -w $(SRC) $(HDRS)
  738. X
  739. Xbundle: README CHANGES pathalias.8 Makefile ${HDRS} ${SRC} arpa-privates make.honey
  740. X    @bundle README CHANGES pathalias.8 Makefile ${HDRS} ${SRC} arpa-privates make.honey
  741. X
  742. Xbundle1: README CHANGES pathalias.8 Makefile ${HDRS}
  743. X    @bundle README CHANGES pathalias.8 Makefile ${HDRS}
  744. X
  745. Xbundle2: addlink.c addnode.c local.c main.c
  746. X    @bundle addlink.c addnode.c local.c main.c
  747. X
  748. Xbundle3: mapit.c mapaux.c
  749. X    @bundle mapit.c mapaux.c
  750. X
  751. Xbundle4: mem.c printit.c parse.y
  752. X    @bundle mem.c printit.c parse.y makedb.c
  753. X
  754. Xbundle5: makedb.c arpatxt.c arpa-privates make.honey
  755. X    @bundle  makedb.c arpatxt.c arpa-privates make.honey
  756. X
  757. Xftp:
  758. X    @make -s bundle | compress > /usr/ftp/pub/honey/pathalias.Z
  759. X
  760. Xmake.honey: makefile
  761. X    @cp makefile make.honey
  762. X
  763. Xlint:    $(LSRC)
  764. X    lint -hbu $(CFLAGS) $(LSRC)
  765. X    lint makedb.c
  766. X
  767. X
  768. X# the remainder is site specific.
  769. X
  770. XLOCAL = paths/citi paths/internet
  771. XFILES = pp/* $(LOCAL)
  772. X
  773. Xpaths/internet: hosts.txt arpa-privates local.hosts arpatxt
  774. X    arpatxt -vfi -g citi -g umix -g mailrus -p arpa-privates local.hosts hosts.txt > paths/internet
  775. X
  776. XAVOID =
  777. X
  778. X# map output (input, really) to lower case; verbose; terminal domains
  779. XARGS = -iD
  780. X
  781. XPARGS=$(ARGS) $(AVOID) $(FILES)
  782. X# desperation debugging -- examine the costs.
  783. Xcosts:
  784. X    pathalias -icvvD ${PARGS} 2>error.costs | awk '{printf("%s\t%s\t%s\n", $$2, $$1, $$3)}' | sort -o pa.costs 
  785. X
  786. X# make one BIG file.  a BIG bad idea.
  787. Xcat:
  788. X    for i in $(FILES); do echo "file {$$i}"; cat $$i; echo 'private {}'; done > CAT
  789. X
  790. X# make a pathparse database.  -g is undocumented.
  791. Xedges:
  792. X    pathalias -g edges $(PARGS) 2>ERRORS > edges.hosts
  793. X#    makedb edges pa
  794. X
  795. X# kill bogus domains with mr. grep, then sort
  796. XPOSTPROC = egrep -v '(\.(com|edu|mil|gov|net|org|arpa|[a-z][a-z])    .*!.*!)|(.\.(com|edu|mil|gov|net|org|arpa|[a-z][a-z])    )' | sort
  797. X
  798. X# round up the usual suspects
  799. Xciti dwon umix mailrus:    $(LOCAL)
  800. X    pathalias -l $@ $(PARGS) | $(POSTPROC) > $@
  801. END_OF_FILE
  802.   if test 3090 -ne `wc -c <'make.honey'`; then
  803.     echo shar: \"'make.honey'\" unpacked with wrong size!
  804.   fi
  805.   # end of 'make.honey'
  806. fi
  807. if test -f 'makedb.c' -a "${1}" != "-c" ; then 
  808.   echo shar: Will not clobber existing file \"'makedb.c'\"
  809. else
  810.   echo shar: Extracting \"'makedb.c'\" \(2342 characters\)
  811.   sed "s/^X//" >'makedb.c' <<'END_OF_FILE'
  812. X/* pathalias -- by steve bellovin, as told to peter honeyman */
  813. X#ifndef lint
  814. Xstatic char    *sccsid = "@(#)makedb.c    9.1 87/10/04";
  815. X#endif /* lint */
  816. X
  817. X#include <stdio.h>
  818. X#include "config.h"
  819. X
  820. Xtypedef struct {
  821. X    char *dptr;
  822. X    int dsize;
  823. X} datum;
  824. X
  825. Xchar *Ofile = ALIASDB, *ProgName;
  826. X
  827. X#define USAGE "%s [-o dbmname] [-a] [file ...]\n"
  828. X
  829. Xmain(argc, argv)
  830. X    char *argv[];
  831. X{    char *ofptr;
  832. X    int c, append = 0;
  833. X    extern int optind;
  834. X    extern char *optarg;
  835. X
  836. X    ProgName = argv[0];
  837. X    while ((c = getopt(argc, argv, "o:a")) != EOF)
  838. X        switch(c) {
  839. X        case 'o':    /* dbm output file */
  840. X            Ofile = optarg;
  841. X            break;
  842. X
  843. X        case 'a':    /* append mode */
  844. X            append++;
  845. X            break;
  846. X
  847. X        default:
  848. X            fprintf(stderr, USAGE, ProgName);
  849. X            exit(1);
  850. X            break;
  851. X        }
  852. X
  853. X
  854. X    if ((ofptr = rindex(Ofile, '/')) != 0)
  855. X        ofptr++;
  856. X    else
  857. X        ofptr = Ofile;
  858. X    if (strlen(ofptr) > 10) {
  859. X        ofptr[10] = 0;
  860. X        fprintf(stderr, "%s: using %s for dbm output\n", ProgName, Ofile);
  861. X    }
  862. X
  863. X    if (append == 0 && dbfile(Ofile) != 0) {
  864. X        perror_(Ofile);
  865. X        exit(1);
  866. X    }
  867. X
  868. X    if (dbminit(Ofile) < 0) {
  869. X        perror_(Ofile);
  870. X        exit(1);
  871. X    }
  872. X
  873. X    if (optind == argc)
  874. X        makedb((char *) 0);
  875. X    else for ( ; optind < argc; optind++)
  876. X        makedb(argv[optind]);
  877. X    exit(0);
  878. X}
  879. X
  880. Xdbfile(dbf)
  881. X    char *dbf;
  882. X{
  883. X    return (dbcreat(dbf, "dir") != 0 || dbcreat(dbf, "pag") != 0);
  884. X}
  885. X
  886. Xdbcreat(dbf, suffix)
  887. X    char *dbf, *suffix;
  888. X{    char buf[BUFSIZ];
  889. X    int fd;
  890. X
  891. X    (void) sprintf(buf, "%s.%s", dbf, suffix);
  892. X    if ((fd = creat(buf, 0666)) < 0)
  893. X        return(-1);
  894. X    (void) close(fd);
  895. X    return(0);
  896. X}
  897. X
  898. X
  899. Xmakedb(ifile)
  900. X    char *ifile;
  901. X{    char line[BUFSIZ];
  902. X    datum key, val;
  903. X
  904. X    if (ifile && (freopen(ifile, "r", stdin) == NULL)) {
  905. X        perror_(ifile);
  906. X        return;
  907. X    }
  908. X
  909. X    /*
  910. X     * keys and values are 0 terminated.  this wastes time and (disk) space,
  911. X     * but does lend simplicity and backwards compatibility.
  912. X     */
  913. X    key.dptr = line;
  914. X    while (fgets(line, sizeof(line), stdin) != NULL) {
  915. X        char *op, *end;
  916. X
  917. X        end = line + strlen(line);
  918. X        end[-1] = 0;    /* kill newline, stuff null terminator */
  919. X        op = index(line, '\t');
  920. X        if (op != 0) {
  921. X            *op++ = 0;
  922. X            key.dsize = op - line;        /* 0 terminated */
  923. X            val.dptr = op;
  924. X            val.dsize = end - op;        /* 0 terminated */
  925. X        } else {
  926. X            key.dsize = end - line;        /* 0 terminated */
  927. X            val.dptr = "\0";        /* why must i do this? */
  928. X            val.dsize = 1;
  929. X        }
  930. X        if (store(key, val) < 0)
  931. X            perror_(Ofile);
  932. X    }
  933. X}
  934. X
  935. Xperror_(str)
  936. X    char    *str;
  937. X{
  938. X    fprintf(stderr, "%s: ", ProgName);
  939. X    perror(str);
  940. X}
  941. END_OF_FILE
  942.   if test 2342 -ne `wc -c <'makedb.c'`; then
  943.     echo shar: \"'makedb.c'\" unpacked with wrong size!
  944.   fi
  945.   # end of 'makedb.c'
  946. fi
  947. echo shar: End of archive 3 \(of 3\).
  948. cp /dev/null ark3isdone
  949. MISSING=""
  950. for I in 1 2 3 ; do
  951.     if test ! -f ark${I}isdone ; then
  952.     MISSING="${MISSING} ${I}"
  953.     fi
  954. done
  955. if test "${MISSING}" = "" ; then
  956.     echo You have unpacked all 3 archives.
  957.     rm -f ark[1-9]isdone
  958. else
  959.     echo You still must unpack the following archives:
  960.     echo "        " ${MISSING}
  961. fi
  962. exit 0
  963. exit 0 # Just in case...
  964.